﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Resources;
using System.Text;

namespace Common.TextMatch
{
    internal sealed class ResourceFacade : ResourceManager
    {

        //Create an instance of the facade
        internal ResourceFacade(string resourceName, Type referenceType)
            : base(GetQualifiedResourceName(resourceName, referenceType), referenceType.Assembly) { }


        //Indexer providing simplified access to the wrapped resource manager
        public string this[string key]
        {
            get { return GetString(key, CultureInfo.CurrentCulture); }
        }


        //Indexer providing simplified access to the wrapped resource manager
        public string this[string key, params object[] parameters]
        {
            get { return String.Format(CultureInfo.CurrentUICulture, GetString(key, CultureInfo.CurrentCulture), parameters); }
        }


        //Determines the qualified name for a resource.  Thsi is useful as VS.NET builds the resource
        //names based on the directory structure where as NAnt relies on specific names.
        private static string GetQualifiedResourceName(string resourceNameSuffix, Type referenceType)
        {
#if VSNET
			AssemblyName simpleName = referenceType.Assembly.GetName();
			string resourceName = (String.Concat(simpleName.Name, ".", referenceType.Namespace, ".", resourceNameSuffix));	
#else
            string resourceName = resourceNameSuffix;
#endif

            return resourceName;
        }

    }
}
